package fr.labri.harmony.analysis.jsep.results;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.Iterator;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Test {
	public static void main(String[] args) throws ClientProtocolException, IOException {
		HttpClient httpclient = HttpClientBuilder.create().build();
		String url = "https://api.github.com/repos/dblock/waffle/issues/37/comments?client_id=2ed17e001bf33de40abc&client_secret=b0eab562ac53c793c606bd27ef40a9e5e4feefc1";
		HttpGet httpget_comment = new HttpGet(url);
		httpget_comment.addHeader("Accept", "application/vnd.github.preview");
		HttpResponse response_comment = httpclient.execute(httpget_comment);
		System.out.println("OK");	
		BufferedReader rd_comment = new BufferedReader
				(new InputStreamReader(response_comment.getEntity().getContent()));

		String line_comment = "";
		String json_comment = "";
		while ((line_comment =rd_comment.readLine()) != null) {
			json_comment += line_comment;
		}
		ObjectMapper mapper_comment = new ObjectMapper();
		JsonNode rootNode_comment = mapper_comment.readTree(json_comment);
		Iterator<JsonNode> ite_comments = rootNode_comment.elements();
		while (ite_comments.hasNext()) {
			JsonNode temp_comment = ite_comments.next();
			StringBuffer body = new StringBuffer();
			body.append("\n");
			body.append("("+temp_comment.get("body").asText()+")");
			body.append("\n");
			
		}
		System.out.println("End Execute query comment...");
		
	}
}
